package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsGoodsProduct;
import com.ruoyi.db.pms.domain.query.PmsGoodsProductQueryVo;
import com.ruoyi.project.pms.service.PmsGoodsProductService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品货品Controller
 *
 * @author ruoyi
 * @date 2020-04-21
 */
@Api(tags="pms管理：商品货品管理")
@RestController
@RequestMapping("/pms/product")
public class PmsGoodsProductController extends BaseController
{
    @Autowired
    private PmsGoodsProductService pmsGoodsProductService;

    @ApiOperation("查询商品货品列表")
    @PreAuthorize("@ss.hasPermi('pms:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsGoodsProductQueryVo pmsGoodsProductQueryVo)
    {
        startPage();
        List<PmsGoodsProduct> list = pmsGoodsProductService.selectPmsGoodsProductList(pmsGoodsProductQueryVo);
        return getDataTable(list);
    }

    /**
     * @author 张涛
     * @return
     */
    @ApiOperation("根据id获取商品货品详细信息")
    @Log(title = "商品货品", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:product:query')")
    @GetMapping(value = "/getProductById/{pid}")
    public TableDataInfo getProductById(@PathVariable("pid") Long pid)
    {
        List<PmsGoodsProduct> list = pmsGoodsProductService.selectPmsGoodsProductByPid(pid);
        return getDataTable(list);
    }

    /**
     * @author 张涛
     * @return
     */
    @ApiOperation("修改商品货品数组")
    @PreAuthorize("@ss.hasPermi('pms:attribute:updateProductList')")
    @RequestMapping(value ="/updateProductList",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateProductList(@RequestBody List<PmsGoodsProduct> list)
    {
        return toAjax(pmsGoodsProductService.updatePmsGoodsProductList(list));
    }

    @ApiOperation("导出商品货品列表")
    @Log(title = "商品货品", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:product:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsGoodsProductQueryVo pmsGoodsProductQueryVo)
    {
        List<PmsGoodsProduct> list = pmsGoodsProductService.selectPmsGoodsProductList(pmsGoodsProductQueryVo);
        ExcelUtil<PmsGoodsProduct> util = new ExcelUtil<PmsGoodsProduct>(PmsGoodsProduct.class);
        return util.exportExcel(list, "product");
    }

    @ApiOperation("获取商品货品详细信息")
    @Log(title = "商品货品", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsGoodsProductService.selectPmsGoodsProductById(id));
    }

    @ApiOperation("新增商品货品")
    @Log(title = "商品货品", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:product:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsGoodsProduct pmsGoodsProduct)
    {
        return toAjax(pmsGoodsProductService.insertPmsGoodsProduct(pmsGoodsProduct));
    }

    @ApiOperation("修改商品货品")
    @Log(title = "商品货品", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:product:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsGoodsProduct pmsGoodsProduct)
    {
        return toAjax(pmsGoodsProductService.updatePmsGoodsProduct(pmsGoodsProduct));
    }

    @ApiOperation("删除商品货品")
    @Log(title = "商品货品", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:product:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsGoodsProductService.deletePmsGoodsProductByIds(ids));
    }
}
